Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Using a Texture Map Alpha Channel

Texture maps whose pixel type is either kQAPixel_ARGB16 or kQAPixel_ARGB32 contain an alpha channel value for each pixel in the map. You can use the alpha channel value to control the transparency of an object on a pixel-by-pixel basis, or you can use the alpha channel value as a blend matte that exposes only certain portions of an image.

To use the alpha channel to control transparency, you should set the drawing engine's transparency blending mode to kQABlend_Premultiply . (You specify an engine's transparency blending mode by assigning a value to its kQATag_Blend state variable.) For pixels of type kQAPixel_ARGB16 , the alpha channel value occupies bit 15; when the value is 1, the pixel is opaque; when the value is 0, the pixel is completely transparent. For pixels of type kQAPixel_ARGB32 , the alpha channel value occupies bits 31 through 24; when the value is 255, the pixel is opaque; when the value is 0, the pixel is completely transparent.

The kQABlend_Premultiply transparency model assumes that the diffuse color of a pixel has been premultiplied by the alpha channel value. As a result, every pixel of the texture map must be premultiplied by its associated alpha channel value before you create the texture map by calling QATextureNew .

Note that the specular highlight is unaffected by the diffuse transparency of an object. As a result, setting an object's alpha channel value to 0 when using the kQABlend_Premultiply transparency blending mode does not cause the object to vanish. The specular highlight is still rendered.

To use the alpha channel as a blend matte to cut out certain portions of a rendered object, you should set the drawing engine's transparency blending mode to kQABlend_Interpolate . If the alpha channel value of all pixels in an object is 0, neither the object nor its specular highlight is rendered. This effectively eliminates the object from the rendered image.

The kQABlend_Interpolate transparency model assumes that the diffuse color of a pixel has not been premultiplied by the alpha channel value. This multiplication is performed by the blending operation.

The kQABlend_Interpolate blending mode cannot render a transparent surface as accurately as the kQABlend_Premultiply mode, because the specular highlight is scaled by the alpha value. In some cases, you can compensate for this behavior by increasing the brightness of the specular highlight.


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |